<?php
//define('ROOT_PATH','sevenel/');
function __autoload($class){
Sf('ext',$class)&&$class='ext';
switch($class){
		case "Smarty" :{
		include($_SERVER['DOCUMENT_ROOT'].ROOT_PATH."Plug-in/smarty/Smarty.class.php");
		break;
		}
		case "xajax" :{
		include($_SERVER['DOCUMENT_ROOT'].ROOT_PATH."Plug-in/xajax/xajax_core/xajax.inc.php");
		break;
		}
		case "ext" :{
		include($_SERVER['DOCUMENT_ROOT'].ROOT_PATH."includes/classes/ext/".$class.".php");
		break;
		}
		default:{
		include($_SERVER['DOCUMENT_ROOT'].ROOT_PATH."includes/classes/".ucfirst($class).".php");
		break;
		}
	}
}
/**array_unique;array 返回不在 $xian 里出现的新数组
 * @param unknown_type $ar
 * @xian str   0 返回不重复数组   1 返回不重复并且不为空
 * @return  array 返回不在 $xian 里出现的新数组
 */
function Au($ar,$xian=0){
	$ar= array_unique($ar);
		switch($xian){
			case 0:{
				return $ar;
			}
			case 1:{
				$var1=array();
				foreach($ar as $valar){
					if($valar!=''){
						$var1[]=$valar;
					}
				}
				return $var1;

			}

			default :{
				$var1=array();
			foreach($ar as $valar){
					if(!in_array($valar,$xian)){
						$var1[]=$valar;
					}

				}
				return $var1;

			}
		}

}
function Dgd($arr){
//tn tablename
//cd condition
//limit num
//sql
//rt  return type json serialize default return array
//start
//count
//column
//tp
//db database handle
//ce  test sql 1 echo sql and exit 2 only echo sql;
	$arg=func_get_args();
	//print_r($arg);
	$arg=$arg[0];
	global ${$arg['db']};
	switch(1){
			case $arg['tn']&&$arg['cd']&&$arg['limit']&&$arg['start']=='':{
				$sql="SELECT * FROM `".${$arg['db']}->getc('prefix')."_".$arg['tn']."` WHERE 1 and ".$arg['cd']." limit ".$arg['limit'].";";
				$arg['column']&&$sql="SELECT ".$arg['column']." FROM `".${$arg['db']}->getc('prefix')."_".$arg['tn']."` WHERE 1 and ".$arg['cd']." limit ".$arg['limit'].";";
				break;
				}
			case $arg['tn']&&$arg['cd']&&$arg['limit']&&$arg['start']!='':{
				$sql="SELECT * FROM `".${$arg['db']}->getc('prefix')."_".$arg['tn']."` WHERE 1 and ".$arg['cd']." limit  ".$arg['start'].",".$arg['limit'].";";
				$arg['column']&&$sql="SELECT ".$arg['column']." FROM `".${$arg['db']}->getc('prefix')."_".$arg['tn']."` WHERE 1 and ".$arg['cd']." limit ".$arg['start'].",".$arg['limit'].";";
				break;
				}
			case $arg['sql']!='':{
				$sql=$arg['sql'];
				break;
				}
			default:{
				$sql="SELECT * FROM `".${$arg['db']}->getc('prefix')."_".$arg['tn']."` WHERE 1 and ".$arg['cd']." ;";
				$arg['column']&&$sql="SELECT ".$arg['column']." FROM `".${$arg['db']}->getc('prefix')."_".$arg['tn']."` WHERE 1 and ".$arg['cd']." ;";				break;
				}
		}
				$arg['ce']==1 && Ja($sql);
				$arg['ce']==1 && exit;
				$arg['ce']==2 && Ja($sql);
				$result_arr=${$arg['db']}->Dqsql($sql);
				//print_r($result_arr);
				if($arg['total']){
				$result_total=${$arg['db']}->Dqsql("SELECT count(*) as arrtotal FROM `".${$arg['db']}->getc('prefix')."_".$arg['tn']."` WHERE 1 and ".$arg['cd'].";");
				$result_arr1['data']=$result_arr;
				$result_arr1['total']=$result_total[0]['arrtotal'];
				$result_arr=$result_arr1;
					}
	if($result_arr){
		if ($arg['limit'] == 1) {
            if($result_arr[0]){
                $result_arr = $result_arr[0];
            }
        }
				//$arg['limit']==1&&$result_arr=$result_arr[0];
				if($arg['tp']){
					Tr($result_arr,$arg['tp']);
					}
				if($arg['rt']=='json'){
				$result_arr=json_encode($result_arr);
					}
				if($arg['rt']=='serialize'){
				$result_arr=serialize($result_arr);
					}
				return $result_arr;
		}else{
				return false;
		}
}

//initialization class
function iniClass($name){
		foreach($name as $value){
		global ${$value['handle']};
		${$value['handle']} = new $value['name']($value['args']);
		Sys::setc($value['name'],$value['handle']);
		//Ja($value['name']);
		}
	}
//initialization js Plug-in
function iniJs($name){
global $jsstr;
		if(!is_array($name)){
			$temp[]=$name;
			$name=$temp;
		}
		foreach($name as $value){
			switch($value){
				case "ext":{
				$jsstr.="<link rel=\"stylesheet\" type=\"text/css\" href=\"".Js_path."/Plug-in/ext/resources/css/ext-all.css\" />
    <script type=\"text/javascript\" charset=\"utf-8\" src=\"".Js_path."/Plug-in/ext/adapter/ext/ext-base.js\"></script>
    <script type=\"text/javascript\" charset=\"utf-8\"  src=\"".Js_path."/Plug-in/ext/ext-all.js\"></script><script type=\"text/javascript\">
	Ext.BLANK_IMAGE_URL = '".Js_path."/Plug-in/ext/resources/images/default/s.gif';
	</script>";

				break;
				}
				case "jsform":{

				break;
				}
				case "my97":{

				break;
				}
				case "lightbox":{
				$jsstr.="<link rel=\"stylesheet\" href=\"/Plug-in/lightbox/css/lightbox.css\" type=\"text/css\" media=\"screen\" />
<script type=\"text/javascript\" src=\"/Plug-in/lightbox/prototype.js\"></script>
<script type=\"text/javascript\" src=\"/Plug-in/lightbox/scriptaculous.js?load=effects\"></script>
<script type=\"text/javascript\" src=\"/Plug-in/lightbox/lightbox.js\"></script>";
				break;
				}
				default:{
				}
			}
		}
	}
/**
 * *********************
 * if No added the function json (javascript object notation) added
 */
if ( !function_exists('json_decode') ){
    function json_decode($content, $assoc=false){
                require_once ($_SERVER['DOCUMENT_ROOT'].ROOT_PATH."includes/classes/Json.php");
                if ( $assoc ){
                    $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
        } else {
                    $json = new Services_JSON;
                }
        return $json->decode($content);
    }
}

if ( !function_exists('json_encode') ){
    function json_encode($content){
                require_once ($_SERVER['DOCUMENT_ROOT'].ROOT_PATH."includes/classes/Json.php");
                $json = new Services_JSON;
        return $json->encode($content);
    }
}
function stripslashes_deep($value)
{
    $value = is_array($value) ?
                array_map('stripslashes_deep', $value) :
                stripslashes($value);

    return $value;
}

function _uri()
{
    if (isset($_SERVER['REQUEST_URI']))
    {
        $uri = $_SERVER['REQUEST_URI'];
    }
    else
    {
        if (isset($_SERVER['argv']))
        {
            $uri = $_SERVER['PHP_SELF'] .'?'. $_SERVER['argv'][0];
        }
        else
        {
            $uri = $_SERVER['PHP_SELF'] .'?'. $_SERVER['QUERY_STRING'];
        }
    }
    return $uri;
}
function Sf($findme,$mystring ){
$pos = strpos($mystring, $findme);
if ($pos === false) {
return false;
} else {
 return true;
}
}

function Tr($value,$tmpname){
global $Tp;
$Tp->assign($tmpname,$value);
}
function Ts($template,$type=0){
  global $Tp;
  $Tp->display($template);
  if($type ==1){
  exit;
  }
}
//��Ľ�.
function Mct(){
    list($usec, $sec) = explode(" ", microtime());
    return 100*(((float)$usec + (float)$sec));
}

//生成gid的值(升级版，author by wangzuolong,建议使用)
function Bic() {
    list($usec, $sec) = explode(" ", microtime());
    $usec = $usec + (rand(1, 400) * rand(400, 900) * rand(900, 1300));
    $sec = $sec + (rand(1, 400) * rand(400, 900) * rand(900, 1300));
    return 100 * (((float) $usec + (float) $sec));
}
function getip(){
  if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
          $ip = getenv("HTTP_CLIENT_IP");
      else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
          $ip = getenv("HTTP_X_FORWARDED_FOR");
      else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
          $ip = getenv("REMOTE_ADDR");
      else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
          $ip = $_SERVER['REMOTE_ADDR'];
      else
          $ip = "unknown";
  return($ip);
}
//��Ľ�.
function Ja($ar,$url=false){
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />

<script language=\"javascript\"  charset=\"utf-8\">
alert('".addslashes($ar)."');";
	if($url){
	echo "window.location ='".$url."';";
	}
echo "</script>";
}

//新函数
function Di($database,$table,$pairs,$type=0){
$app= new Dbt('d_'.$database,$table,$pairs);
return $app->getInsertSQL($type);
}
function Du($database,$table,$pairs,$a,$b,$type=0){
$app= new Dbt('d_'.$database,$table,$pairs);
return $app->getUpdateSQL($a,$b,$type);
}
function Dd($database,$table,$a,$b,$type=0,$num){
$app= new Dbt('d_'.$database,$table,$pairs);
return $app->getDeleteSQL($a,$b,$type,$num);
}
function get_naps_bot()
{
        $useragent = strtolower($_SERVER['HTTP_USER_AGENT']);

        if (strpos($useragent, 'googlebot') !== false){
				exit;
				exit;

        }

        if (strpos($useragent, 'msnbot') !== false){
				exit;
				exit;
        }

        if (strpos($useragent, 'slurp') !== false){
				exit;
				exit;
        }

        if (strpos($useragent, 'baiduspider') !== false){
				exit;
				exit;
        }

        if (strpos($useragent, 'sohu-search') !== false){
				exit;
				exit;
        }

        if (strpos($useragent, 'lycos') !== false){
				exit;
				exit;
        }

        if (strpos($useragent, 'robozilla') !== false){
				exit;
				exit;
				}
}
//get_naps_bot();
//!eregi('win',$_SERVER['HTTP_USER_AGENT'])&&exit;

function adxx($string) {
		if(!get_magic_quotes_gpc()) {
			if(is_array($string)) {
				foreach($string as $key => $val) {
					$string[$key] = adxx($val);
				}
			} else {
				$string = addslashes($string);
			}
		}
		return $string;
	}

function Jt($url,$text="",$time="0.5",$go="0",$templates="loading.html"){
     global $Tp;
         if (!isset($url)) {
              $url="/index.php";
         }
		 $time*=1000;
		 if($go!="0"){
			echo "<script LANGUAGE=\"Javascript\">";
			echo "window.location= \"$url\" ";
			echo "</script>";
			exit;
		 }
         $Tp->assign('url',$url);
	     $Tp->assign('msg',$text);
		 $Tp->assign('time',$time);
        Ts($templates);
      exit();
}

function Jc($var){ global $_POST ,$_GET,$_FILES,$_SESSION,$_REQUEST,$_SERVER,$_COOKIE,$ttt;

	print("<pre>");
switch ($var)
	{
	  case 'p':
	  	print_r($_POST);
		break;
	  case 'g':
	  	print_r($_GET);
		break;
	  case 'r':
	  	print_r($_REQUEST);
		break;
	  case 's':
	  	print_r($_SESSION);
		break;
	  case 'f':
	  	print_r($_FILES);
		break;
	  case 'c':
	  	print_r($_COOKIE);
		break;
	  case 'e':
	  	print_r($_SERVER);
		break;
	  case 't':
		$ttt->debugging = true;
		break;
	default:
		  	print_r($var);
	}
print("</pre>");
}
function judge($para){
	return $para?'<font color=green>支持<b>√</b></font>':'<font color=red>不支持<b>×</b></font>';
	}
function ext_request($msg){
		echo "{success:true,msg:'$msg'}";
		exit();
	}
function ext_request_failure($msg){
		echo "{success:false,msg:'$msg'}";
		exit();
	}
function randomkeys($length)
  {
   $pattern = "1234567890abcdefghijklmnopqrstuvwxyz";
   for($i=0;$i<$length;$i++)
   {
     $key .= $pattern{rand(0,35)};
   }
   return $key;
  }
function gettabname($parent_id,$prefix,$noprefix=false){
	$table=Dgd(array(
		  'db'=>'d_sevenel',
		  'cd'=>"id = $parent_id",
		  'tn'=>"datamod",
		  'limit'=>'1'
		  ));
		if($noprefix){
			return $table['tabname'];
		}else{
		$tabname = $prefix.'_'.$table['tabname'];
		return $tabname;
		}
}
function getItemType($items_array,$compare){
	foreach($items_array as $arrow=>$value){
					if($value['value']==$compare){
						$type = $value['type'];
					}
		}
		$type==''&&$type = " varchar(50) NOT NULL";
	return $type;
}
function getCommend($value){
	if($value==''){
					$value='';
				}else{
					$value=" COMMENT '".$value."'";
				}
	return $value;
}
function get_date($format,$timestamp = ''){
		$timeoffset = 8;
		empty($timestamp) && $timestamp = time();
		return gmdate($format,$timestamp+$timeoffset*3600);
	}
function is_odd($num){
			if($num%2==0){
				return false;
			}
			else{
				return true;
			}
		}
function tableid($tp,$table,$id){
				$temp=Dgd(array(
					  'db'=>'d_sevenel',
					  'cd'=>"id = '".$id."' ",
					  'tn'=>$table,
					  'limit'=>1,
					  'tp'=>$tp
					));
	}
function Dga($name,$var,$tttttt=0){
$sql="SELECT * FROM `se_".$name."` WHERE 1 and ".$var." limit 1;";
if($tttttt!=0)
{echo $sql;
exit;
}mysql_query("Set Names '".DEFAULT_CHARSET."' ");
$resouce=mysql_query($sql);
if($temp=mysql_fetch_assoc($resouce)){
//echo $temp."is".$temp[0];
return $temp;
}
else
{
return false;
}
}

function Dgs($name,$var,$tttttt=0){
global $prefix;
$sql="SELECT * FROM se_".$name." WHERE 1 and ".$var.";";
if($tttttt!=0)
{echo $sql;
exit;
}//echo $sql;
mysql_query("Set Names '".DEFAULT_CHARSET."' ");
$resouce=mysql_query($sql);

$nownum=mysql_num_rows($resouce);
while($temp=mysql_fetch_array($resouce))
{
$temp[znum]=$nownum;
$t[]=$temp;
//print_r($t);
}

if($t){
return $t;
}
else
{
return false;
}
}

function fy(
			$param=array(
				'result'	=>'result',
				'table'		=>'',
				'condition'	=>'',
				'perpage'	=>8,
				'type'		=>1,
				'nav'		=>'nav',
				'pagename'	=>'page',
				'debug'
				)
){
	$result		=	$param['result']==''?'result':$param['result'];
	$table		=	$param['table'];
	$condition	=	$param['condition'];
	$perpage	=	$param['perpage']==''?8:$param['perpage'];
	$type		=	$param['type']==''?1:$param['type'];
	$nav		=	$param['nav']==''?'nav':$param['nav'];
	$page_name	=	$param['page_name']==''?'page':$param['page_name'];

	//配置搜索
	!$condition && $condition=1;
	!$result && $result='result';
	!$nav && $nav='nav';
	$sql = "SELECT count(id) as num
		FROM se_{$table}
		where 1  and del!=1  and ".$condition;
		
	$res = mysql_query($sql);

	$num_row = mysql_num_rows($res);
	if(strrpos($condition,'group by')!==false){
		$temp['num'] = $num_row;
	}else{
		$temp = mysql_fetch_array($res);
	}
	//每页
	$perpage = $perpage;
	!$_GET[$page_name] && $_GET[$page_name] = 1;
	$ajaxpage = new lm_page( array ('total'=>$temp[num], 'perpage'=>$perpage,'page_name'=>$page_name));
	mysql_free_result($res);
	Tr($ajaxpage->show($type),$nav);

	if($param['debug']!=''){

		Jc('<b>SQL:</b><br />');
		Jc("SELECT * FROM se_{$table} WHERE 1 AND del!=1 and {$condition} limit ".($_GET[$page_name]-1)*$perpage.",".$perpage);

		Jc('<b>Result:</b><br />');
		Jc(Dgs($table,"del!=1 and {$condition} limit ".($_GET[$page_name]-1)*$perpage.",".$perpage));

		Jc('<b>SQL:</b><br />');
		Dgs($table,"del!=1 and {$condition} limit ".($_GET[$page_name]-1)*$perpage.",".$perpage,1);
	}
	$R=Dgs($table,"del!=1 and {$condition} limit ".($_GET[$page_name]-1)*$perpage.",".$perpage.$debug);
	Tr($R,$result);
	return $R;
}
function cutstr($string, $sublen, $start = 0, $code = 'UTF-8'){
    if($code == 'UTF-8')
    {
        $pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/";
        preg_match_all($pa, $string, $t_string);

        if(count($t_string[0]) - $start > $sublen) return join('', array_slice($t_string[0], $start, $sublen))."...";
        return join('', array_slice($t_string[0], $start, $sublen));
    }
    else
    {
        $start = $start*2;
        $sublen = $sublen*2;
        $strlen = strlen($string);
        $tmpstr = '';

        for($i=0; $i<$strlen; $i++)
        {
            if($i>=$start && $i<($start+$sublen))
            {
                if(ord(substr($string, $i, 1))>129)
                {
                    $tmpstr.= substr($string, $i, 2);
                }
                else
                {
                    $tmpstr.= substr($string, $i, 1);
                }
            }
            if(ord(substr($string, $i, 1))>129) $i++;
        }
        if(strlen($tmpstr)<$strlen ) $tmpstr.= "...";
        return $tmpstr;
    }
}

function createthumb($src,$otype,$album,$wd,$hd,$ml,$im_des){
	if($otype!=".bmp")
	{
	$type=strtolower($otype);
	if($im_des==''){
	$im_des="../../uplods/thumb".$ml."/".$album.".jpg";
	}
	if($type==".jpg"||$type==".jpeg")
		$im=@imagecreatefromjpeg($src);
	if($type==".gif")
		$im=@imagecreatefromgif($src);
	if($type==".png")
		$im=@imagecreatefrompng($src);
	$width=@imagesx($im);
	$height=@imagesy($im);
	@$ratio=$height/$width;
	if($ratio<0.9)
	{
		$newwidth=$wd;
		@$newheight=$height*($wd/$width);
	}
	else
	{
		$newheight=$hd;
		$newwidth=$width*($hd/$height);
	}
	$im_s=@imagecreatetruecolor($newwidth,$newheight);
	@imagecopyresized($im_s,$im,0,0,0,0,$newwidth,$newheight,$width,$height);
	@imagejpeg($im_s,$im_des,70);
	chmod($im_des,0777);
	@imagedestroy($im);
	}
}
/*
* 功能：PHP图片水印 (水印支持图片或文字)
* 参数：
*      $groundImage    背景图片，即需要加水印的图片，暂只支持GIF,JPG,PNG格式；
*      $waterPos        水印位置，有10种状态，0为随机位置；
*                        1为顶端居左，2为顶端居中，3为顶端居右；
*                        4为中部居左，5为中部居中，6为中部居右；
*                        7为底端居左，8为底端居中，9为底端居右；
*      $waterImage        图片水印，即作为水印的图片，暂只支持GIF,JPG,PNG格式；
*      $waterText        文字水印，即把文字作为为水印，支持ASCII码，不支持中文；
*      $textFont        文字大小，默认为12；以像素为单位
*      $textColor        文字颜色，值为十六进制颜色值，默认为#FF0000(红色)；
*
* 注意：Support GD 2.0，Support FreeType、GIF Read、GIF Create、JPG 、PNG
*      $waterImage 和 $waterText 最好不要同时使用，选其中之一即可，优先使用 $waterImage。
*      当$waterImage有效时，参数$waterString、$stringFont、$stringColor均不生效。
*      加水印后的图片的文件名和 $groundImage 一样。
* 作者：longware @ 2004-11-3 14:15:13
* 修改：Zuolong @ 2010年01月29日 星期五 14时34分54秒 
*       对文字水印的修改。默认字体设定为文泉驿微米黑
*/
function imageWaterMark($groundImage,$bcmz,$waterPos=0,$waterImage="",$waterText="",$textFont=12,$syzt="wqy-microhei-lite.ttc",$textColor="#FF0000")
{
    $isWaterImage = FALSE;
    $formatMsg = "暂不支持该文件格式，请用图片处理软件将图片转换为GIF、JPG、PNG格式。";
    $font_file="../fonts/".$syzt;     //字体路径：文字水印

    //读取水印文件
    if(!empty($waterImage) && file_exists($waterImage))
    {
        $isWaterImage = TRUE;
        $water_info = getimagesize($waterImage);
        $water_w    = $water_info[0];//取得水印图片的宽
        $water_h    = $water_info[1];//取得水印图片的高

        switch($water_info[2])//取得水印图片的格式
        {
            case 1:$water_im = imagecreatefromgif($waterImage);break;
            case 2:$water_im = imagecreatefromjpeg($waterImage);break;
            case 3:$water_im = imagecreatefrompng($waterImage);break;
            default:ja($formatMsg);
        }
    }

    //读取背景图片
    if(!empty($groundImage) && file_exists($groundImage))
    {
        $ground_info = getimagesize($groundImage);
        $ground_w    = $ground_info[0];//取得背景图片的宽
        $ground_h    = $ground_info[1];//取得背景图片的高

        switch($ground_info[2])//取得背景图片的格式
        {
            case 1:$ground_im = imagecreatefromgif($groundImage);break;
            case 2:$ground_im = imagecreatefromjpeg($groundImage);break;
            case 3:$ground_im = imagecreatefrompng($groundImage);break;
            default:ja($formatMsg);
        }
    }
    else
    {
        Ja("需要加水印的图片不存在！");
    }

    //水印位置
    if($isWaterImage)//图片水印
    {
        $w = $water_w;
        $h = $water_h;
        $label = "图片的";
    }
    else//文字水印
    {
        $temp = imagettfbbox($textFont,0,$font_file,$waterText);//取得使用 TrueType 字体的文本的范围
        $w = $temp[2] - $temp[6];
        $h = $temp[3] - $temp[7];
        unset($temp);
        $label = "文字区域";
    }
    if( ($ground_w<$w) || ($ground_h<$h) )
    {
       ja("需要加水印的图片的长度或宽度比水印".$label."还小，无法生成水印！");
        return;
    }
    switch($waterPos)
    {
        case 0://随机
            $posX = rand(0,($ground_w - $w));
            $posY = rand(0,($ground_h - $h));
            break;
        case 1://1为顶端居左
            $posX = 0;
            $posY = 0;
            break;
        case 2://2为顶端居中
            $posX = ($ground_w - $w) / 2;
            $posY = 0;
            break;
        case 3://3为顶端居右
            $posX = $ground_w - $w;
            $posY = 0;
            break;
        case 4://4为中部居左
            $posX = 0;
            $posY = ($ground_h - $h) / 2;
            break;
        case 5://5为中部居中
            $posX = ($ground_w - $w) / 2;
            $posY = ($ground_h - $h) / 2;
            break;
        case 6://6为中部居右
            $posX = $ground_w - $w;
            $posY = ($ground_h - $h) / 2;
            break;
        case 7://7为底端居左
            $posX = 0;
            $posY = $ground_h - $h;
            break;
        case 8://8为底端居中
            $posX = ($ground_w - $w) / 2;
            $posY = $ground_h - $h;
            break;
        case 9://9为底端居右
            $posX = $ground_w - $w;
            $posY = $ground_h - $h;
            break;
        default://随机
            $posX = rand(0,($ground_w - $w));
            $posY = rand(0,($ground_h - $h));
            break;
    }

    //设定图像的混色模式
    imagealphablending($ground_im, true);

    if($isWaterImage)//图片水印
    {
        imagecopy($ground_im, $water_im, $posX, $posY, 0, 0, $water_w,$water_h);//拷贝水印到目标文件
    }
    else//文字水印
    {
        if( !empty($textColor) && (strlen($textColor)==7) )
        {
            $R = hexdec(substr($textColor,1,2));
            $G = hexdec(substr($textColor,3,2));
            $B = hexdec(substr($textColor,5));
        }
        else
        {
            ja("水印文字颜色格式不正确！");
        }
        if(!is_file($font_file)){
            ja("水印文字字体不存在！请将字体复制至此：{$font_file}");
        }
        //imagestring ( $ground_im, $textFont, $posX, $posY, $waterText, imagecolorallocate($ground_im, $R, $G, $B));
        imagettftext ( $ground_im, $textFont, 0, $posX, $posY, imagecolorallocate($ground_im, $R, $G, $B), $font_file, $waterText);
    }

    //生成水印后的图片
    @unlink($bcmz);
    switch($ground_info[2])//取得背景图片的格式
    {
        case 1:imagegif($ground_im,$bcmz);break;
        case 2:imagejpeg($ground_im,$bcmz);break;
        case 3:imagepng($ground_im,$bcmz);break;
        default:ja($errorMsg);
    }

    //释放内存
    if(isset($water_info)) unset($water_info);
    if(isset($water_im)) imagedestroy($water_im);
    unset($ground_info);
    imagedestroy($ground_im);
}
/*
　　方法1：

RewriteEngine on 
RewriteCond %{HTTP_USER_AGENT} ^Baiduspider [NC] 
RewriteRule .* - [F]

　　方法2：

SetEnvIfNoCase User-Agent "^Baiduspider" bad_bot

<Limit GET POST> 
Order Allow,Deny 
Allow from all 
Deny from env=bad_bot 
</Limit>
*/
/* * function Dz($sql) zhisql
 *
 *
 *
 */

function Dz($sql, $ttttt=0) {
    global $db;
    mysql_query("Set Names '" . DEFAULT_CHARSET . "' ");
    if ($ttttt != 0) {
        echo $sql;
        exit;
    }
    $result = mysql_query($sql);
    while ($temp = mysql_fetch_array($result)) {
        $tempa[] = $temp;
    }
    mysql_free_result($result);
    return $tempa;
}

/**
 * *******************
 * 去除所有的html标签
 */
function clearhtml($str) {
    $strtemp = trim($str);
    $search = array(
        "|'|Uis",
        "|<script[^>]*?>.*?</script>|Uis", // 去掉 javascript
        "|<[\/\!]*?[^<>]*?>|Uis", // 去掉 HTML 标记
        "'&(quot|#34);'i", // 替换 HTML 实体
        "'&(amp|#38);'i",
        "|,|Uis",
        "|[\s]{2,}|is",
        "[&nbsp;]isu",
        "|[$]|Uis",
    );
    $replace = array(
        "`",
        "",
        "",
        "",
        "","",
 " ",
 " ",
 " dollar ",
);
$text = preg_replace($search, $replace, $strtemp);
return $text;
}
/**
 * 计算日期差
 *  写了一个5.3新增的函数 date_diff。现更名 为date_diff_bic
 *
 * @param string time $date1	Y-m-d H:i:s
 * @param string time $date2	Y-m-d H:i:s
 * @param string $return_type
 * 		返回类型:'s'-秒	'i'-分	'h'-小时		'd'-天	'w'-星期		'm'-月	'y'-年
 * 		默认:'d'-天
 * @param bool $ceil
 * 		是否四舍五入
 * 		默认:false
 * @return numeric
 * @author Bic
 * 		2009年9月26日 10时28分46秒
 * 		2010年6月9日   修改函数名
 */
function date_diff_bic($date1, $date2, $return_type='d',$ceil=false) {
    $timestamp1 = is_numeric($date1)?$date1:strtotime($date1);
    $timestamp2 = is_numeric($date2)?$date2:strtotime($date2);
    switch ($return_type){
        case 's':
        case 'second':
            $result = ($timestamp2-$timestamp1);
            break;
        case 'i':
        case 'minute':
            $result = ($timestamp2-$timestamp1)/60;
            break;
        case 'h':
        case 'hour':
            $result = ($timestamp2-$timestamp1)/3600;
            break;
        case 'd':
        case 'day':
            $result = ($timestamp2-$timestamp1)/86400;
            break;
        case 'w':
        case 'week':
            $result = ($timestamp2-$timestamp1)/604800;
            break;
        case 'm':
        case 'month':
            $result = ($timestamp2-$timestamp1)/2592000;
            break;
        case 'y':
        case 'year':
            $result = ($timestamp2-$timestamp1)/946080000;
            break;
    }
    return $ceil?ceil($result):floor($result);
}

//网站关键词
function the_seo($t){
    static $info;
    global $lang;
    $t = $t==''?'tt':$t;
    if ($info==''){
        $n = trim($_SERVER['PHP_SELF'],'/');
        $info = Dga('seo',"del!=1 {$lang} and self='{$n}' and tid=100");
        if ($info==''){
            $info = Dga('seo',"del!=1 {$lang} and self='index.php' and tid=100");
        }
    }
    return $info[$t];
}

//UBB
function Bubb($textname, $info, $height, $width, $rootpath='', $ToolbarSet='0', $ToolbarStartExpanded='true', $skin='default', $language='zh-cn') {
    //Ja($rootpath."/includes/ubb/fckeditor.php");
    require_once (BIC_ROOT . "Plug-in/fck/fckeditor.php");
    $sBasePath = "/Plug-in/fck/";
   //Ja($rootpath."/includes/ubb/fckeditor.php");
    $oFCKeditor = new FCKeditor($textname);
    $oFCKeditor->BasePath = $sBasePath;
    $oFCKeditor->Width = $width;
    $oFCKeditor->Height = $height;
    $oFCKeditor->Config['AutoDetectLanguage'] = false;
    $oFCKeditor->Config['DefaultLanguage'] = $language;
    $ToolbarSet != 0 && $oFCKeditor->ToolbarSet = 'Basic';
    $oFCKeditor->Config['ToolbarStartExpanded'] = $ToolbarStartExpanded;
    //$skin office2003  silver
    $oFCKeditor->Config['SkinPath'] = $sBasePath . 'editor/skins/' . htmlspecialchars($skin) . '/';
    $oFCKeditor->Value = $info;
    $oFCKeditor->Create();
}
?>
